package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.MemberThreadLocal;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    /**
     * 查询取消预约数量
     * @return 取消预约数量
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long memberId = MemberThreadLocal.getMemberId();
        return R.ok(reservationService.getCancelledReservationCount(memberId));
    }

    /**
     * 新增预约
     * @param reservationDto 预约信息Dto
     * @return 新增结果
     */
    @ApiOperation("新增预约")
    @PostMapping
    public AjaxResult addReservation(@RequestBody ReservationDto reservationDto) {
        reservationService.addReservation(reservationDto);
        return AjaxResult.success();
    }


    /**
     * 分页查询预约列表
     * @param pageNum 页码
     * @param pageSize 每页数量
     * @param status 状态
     * @return 预约列表
     */
    @ApiOperation("分页查询预约列表")
    @GetMapping("/page")
    public R<TableDataInfo<Reservation>> page(Integer pageNum, Integer pageSize, Integer status) {
        return R.ok(reservationService.page(pageNum, pageSize, status));
    }

    /**
     * 取消预约
     * @param id 预约id
     * @return 取消结果
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelReservation(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return AjaxResult.success();
    }

    /**
     * 根据时间查询预约数量
     * @param time 时间
     * @return 预约数量
     */
    @GetMapping("/countByTime")
    @ApiOperation("根据时间查询预约数量")
    public R<List<TimeCountVo>> countByTime(@RequestParam Long time) {
        return R.ok(reservationService.countByTime(time));
    }

}